package cn.springcloud.alibaba.ums.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/test")
public class TestController {

	@Autowired
	private RestTemplate restTemplate;
	@Autowired
	private LoadBalancerClient loadBalancerClient;

	@GetMapping(value = "/test0")
	public String test0() {
		ServiceInstance instance = loadBalancerClient.choose("springcloud-alibaba-auth");
		String url = "http://" + instance.getHost() + ":" + instance.getPort() + "/auth/test/get";
		RestTemplate restTemplate = new RestTemplate();
		return restTemplate.getForObject(url, String.class);
	}

	@GetMapping(value = "/test1")
	public String test1() {
		String url = "http://springcloud-alibaba-auth/auth/test/get";
		return restTemplate.getForObject(url, String.class);
	}
}
